package com.dandelion.manager.commons.tag;

import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.support.DefaultSubjectContext;

import com.dandelion.commons.constants.BaseConst;

public class Functions {
	
	/**
	 * 获取用户登录账号
	 * @param session
	 * @return
	 */
    public static String principal(Session session) {
        PrincipalCollection principalCollection =(PrincipalCollection) session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
        if(null != principalCollection) {
        	return (String)principalCollection.getPrimaryPrincipal(); 
        } else {
        	return "发生错误，用户非正常退出。";
        }
    }
    
    /**
     * 强制注销登录用户
     * @param session
     * @return
     */
    public static boolean isForceLogout(Session session) {
        return session.getAttribute(BaseConst.SESSION_FORCE_LOGOUT_KEY) != null;
    }
}
